import {createAction, createThunkAction} from "../../lib/redux-utils";
import {get, postForm, postJson} from "../../lib/http";
import {getPrincipal} from "../../lib/identity";

const principal = getPrincipal();

export const showCreate = createAction("CARRIER.SHOW_CREATE");
export const hideCreate = createAction("CARRIER.HIDE_CREATE");
export const showModify = createAction("CARRIER.SHOW_MODIFY");
export const hideModify = createAction("CARRIER.HIDE_MODIFY");
export const showCreateRate = createAction("CARRIER.SHOW_CREATE_RATE");
export const hideCreateRate = createAction("CARRIER.HIDE_CREATE_RATE");
export const showUpdateRate = createAction("CARRIER.SHOW_UPDATE_RATE");
export const hideUpdateRate = createAction("CARRIER.HIDE_UPDATE_RATE");
export const updateCarrierModel = createAction("CARRIER.UPDATE_CARRIER_MODEL");
export const showCreateLinePrice = createAction("CARRIER.SHOW_CREATE_LINE_PRICE");
export const hideCreateLinePrice = createAction("CARRIER.HIDE_CREATE_LINE_PRICE");
export const showUpdateLinePrice = createAction("CARRIER.SHOW_UPDATE_LINE_PRICE");
export const hideUpdateLinePrice = createAction("CARRIER.HIDE_UPDATE_LINE_PRICE");
export const updateLinePriceModel = createAction("CARRIER.HIDE_UPDATE_LINE_PRICE_MODEL");
export const updateBaoGuanFee = createAction("CARRIER.UPDATE_BAOGUAN_FEE");
export const updateVehicleFees = createAction("CARRIER.VEHICLE_FEE");
export const updatelines = createAction("CARRIER.UPDATE_LINES");
export const updateLinePriceInCreateModel = createAction("CARRIER.UPDATE_LINE_PRICE_IN_CREATE_MODEL");
export const addLinePriceInCreateModel = createAction("CARRIER.ADD_LINE_PRICE_IN_CREATE_MODEL");

export const getById = createThunkAction('CARRIER.GET', params =>
    get('/carrier/' + params)
);
export const query = createThunkAction("CARRIER.QUERY", params =>
    postJson("/carrier/query", params)
);
export const modify = createThunkAction("CARRIER.MODIFY", params =>
    postJson("/carrier/modify", params)
);
export const create = createThunkAction("CARRIER.CREATE", params =>
    postJson("/carrier/create", params)
);
export const del = createThunkAction("", params =>
    get("/carrier/del/" + params + "/" + principal.id)
);
export const getCommonRate = createThunkAction("CARRIER.GET_COMMON_RATE", params =>
    get("/rate/getCommon")
);
export const getCurrencyList = createThunkAction("CARRIER.GET_CURRENCY", () =>
    get("/rate/currency")
);
export const getFeeList = createThunkAction("CARRIER.GET_FEE_LIST", () =>
    get("/feeItem/all")
);
export const createLinePrice = createThunkAction("CARRIER.CREATE_LINE_PRICE", params =>
    postJson("/linePrice/create", params)
);
export const queryLinePrice = createThunkAction("CARRIER.QUERY_LINE_PRICE", params =>
    postJson("/linePrice/query", params)
);
export const updateLinePrice = createThunkAction("CARRIER.UPDATE_LINE_PRICE", params =>
    postJson("/linePrice/modify", params)
);
export const getBusinessList = createThunkAction("CARRIER.GET_BUSINESS", () =>
    postJson("/bsCode/getAll", {})
);
export const deleteLinePrice = createThunkAction("CARRIER.DELETE_LINE_PRICE", params =>
    get("/linePrice/del/" + params + "/" + getPrincipal().id)
);
export const getTransportType = createThunkAction("CARRIER.GET_TRANSPORT_TYPE", params =>
    get("/transportType/all")
);
export const lineImport = createThunkAction("CARRIER.LINE_IMPORT", params =>
    postForm("/linePrice/lineImport/" + params.belongId + "/" + params.opId + "/" + params.organizationId, params)
);
export const importCarrier = createThunkAction("CARRIER.IMPORT", params =>
    postForm("/carrier/import/" + params.opId, params)
);
export const importVehicle = createThunkAction("CARRIER.IMPORT_VEHICLE", params =>
    postForm("/carrier/importVehicle/" + params.belongId, params)
);
export const lineImportInCreateModal = createThunkAction("CARRIER.IMPORT_LINE_IN_CREATE_MODAL", params =>
    postForm("/linePrice/importLineInCreateModal", params)
);

